#include "StdAfx.h"
#include "AVWData.h"
#include <string.h>

AVWData::AVWData(void)
{
	this->A = 0.0;
	this->V = 0.0;
	this->W = 0.0;
}

AVWData::~AVWData(void)
{
}
void AVWData::toBinaryDisplay(char* szAVWDataDisplay)
{
	char szA[INTEGER_LENGTH+DECIMAL_LENGTH+1];
	char szV[INTEGER_LENGTH+DECIMAL_LENGTH+1];
	char szW[INTEGER_LENGTH+DECIMAL_LENGTH+1];
	szA[INTEGER_LENGTH+DECIMAL_LENGTH] = '\0';
	szV[INTEGER_LENGTH+DECIMAL_LENGTH] = '\0';
	szW[INTEGER_LENGTH+DECIMAL_LENGTH] = '\0';
	this->_parseUtil.floatToBinary(this->A, szA, 2, false);
	this->_parseUtil.floatToBinary(this->V, szV, 2, false);
	this->_parseUtil.floatToBinary(this->W, szW, 2, false);
	strcpy(szAVWDataDisplay, szA);
	strcat(szAVWDataDisplay, szV);
	strcat(szAVWDataDisplay, szW);
	this->setFrame(szAVWDataDisplay);
}

void AVWData::getFrameField(int fieldNo, char* szFrameFieldString)
{
	int indexFieldSize[AVWDATA_FIELDS_COUNT] = {FLOAT_TYPE_LENGTH,
												FLOAT_TYPE_LENGTH,
												FLOAT_TYPE_LENGTH
												};
	int indexFieldStart[AVWDATA_FIELDS_COUNT] = {0,
												FLOAT_TYPE_LENGTH,
												2*FLOAT_TYPE_LENGTH,
												};
	_parseUtil.partitionFrameString(szFrameFieldString, indexFieldStart[fieldNo], indexFieldSize[fieldNo], this->szFrameData);
}

void AVWData::setFrame(char* szFrameString)
{
	strcpy(this->szFrameData, szFrameString);
}

void AVWData::setPropertiesFromFrameData()
{
	char szTmpA[FLOAT_TYPE_LENGTH+1] = "";
	char szTmpV[FLOAT_TYPE_LENGTH+1] = "";
	char szTmpW[FLOAT_TYPE_LENGTH+1] = "";
	this->getFrameField(FLOAT_A_FIELD, szTmpA);
	this->A = this->_parseUtil.binaryToFloat(szTmpA);
	this->getFrameField(FLOAT_V_FIELD, szTmpV);
	this->V = this->_parseUtil.binaryToFloat(szTmpV);
	this->getFrameField(FLOAT_W_FIELD, szTmpW);
	this->W = this->_parseUtil.binaryToFloat(szTmpW);
}